package dmqm.mall.controller;

import dmqm.mall.model.Product;
import dmqm.mall.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @RequestMapping("/get/{id}")
    public Product GetProduct(@PathVariable int id) {
        return productService.Get(id);
    }

    @RequestMapping("/add")
    public boolean AddProduct(@RequestBody Product product) {
        if (product.getName().equals(""))
            return false;
        return productService.Add(product);
    }

    @RequestMapping("/update")
    public boolean UpdateProduct(@RequestBody Product product) {
        return productService.Update(product);
    }

    @RequestMapping("/del/{id}")
    public boolean DeleteProduct(@PathVariable int id) {
        return productService.Delete(id);
    }

    @RequestMapping("/list")
    public List GetProductList() {
        return productService.List();
    }
}
